import request, { type ListResponse, type ListQuery } from "@/utils/request";
import { type ExpressCompanyType } from "./company";

const EXPRESS_BASE_URL = "/api/internal/expressOrder";

export const ExpressAPI = {
  getExpressList: (params: ListQuery) => {
    return request.get<any, ListResponse<ExpressType>>(`${EXPRESS_BASE_URL}/`, {
      params,
    });
  },
  getExpressDetail: (id: number) => {
    return request.get(`${EXPRESS_BASE_URL}/${id}/`);
  },
  createExpress: (data: Partial<ExpressForm>) => {
    return request.post(`${EXPRESS_BASE_URL}/`, data);
  },
  updateExpress: (data: Partial<ExpressForm>) => {
    return request.put(`${EXPRESS_BASE_URL}/${data.id}/`, data);
  },
  deleteExpress: (id: number) => {
    return request.delete(`${EXPRESS_BASE_URL}/${id}/`);
  },
};

export type ExpressListQuery = {} & ListQuery;

export type ExpressType = {
  id: number;
  company: ExpressCompanyType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  code: string;
  origin: string;
};

export type ExpressForm = {
  id?: number;
  code: string;
  origin: string;
  company: number | "";
};

export type ExpressStatusType = "pending" | "shipped" | "delivered" | "returned";

export default ExpressAPI;
